import Http from './Http';
class Api extends Http {
  constructor() {
    super();
    // console.log(this)
  }
  //获取参赛人物
  async findNewVoteArtistList(page, pageSize) {
    return this.post({
      url: '/customize/findNewVoteArtistList',
      data: {
        customizeId: 1,
        page,
        pageSize,
      },
      after: (res) => {
        // localStorage.setItem("APP_TOKEN", res.data.message);
        this.setImg(res.data.data.list, 'titleImg');
        return res.data.data;
      },
    });
  }
  //关键字查询证书
  async findCertificate(data) {
    return await this.post({
      url: '/certificate/findCertificate',
      data,
      before: (ctx) => ctx,
      after: (res) => {
        return res.data.data;
      },
    });
  }
  async ossUploadEntryFile(data) {
    return await this.post({
      url: '/customize/ossUploadEntryFile',
      data,
      before: (ctx) => ctx,
      after: (res) => {
        return res.data.data;
      },
    });
  }
  //城市公益巡演
  async selectNewsList(page, pageSize) {
    return this.get({
      url: '/news/selectNewsList',
      data: {
        category: 9,
        page,
        pageSize,
      },
      after: (res) => {
        // localStorage.setItem("APP_TOKEN", res.data.message);
        this.setImg(res.data.data.list, 'titleImg');
        return res.data.data;
      },
    });
  }
  //往期回顾
  async selectNewsList8(page, pageSize) {
    return this.get({
      url: '/news/selectNewsList',
      data: {
        category: 8,
        page,
        pageSize,
      },
      after: (res) => {
        // localStorage.setItem("APP_TOKEN", res.data.message);
        this.setImg(res.data.data.list, 'titleImg');
        return res.data.data;
      },
    });
  }
  //大赛报道
  async selectNewsList7(page, pageSize) {
    return this.get({
      url: '/news/selectNewsList',
      data: {
        category: 7,
        page,
        pageSize,
      },
      after: (res) => {
        // localStorage.setItem("APP_TOKEN", res.data.message);
        this.setImg(res.data.data.list, 'titleImg');
        return res.data.data;
      },
    });
  }
  //委员会
  async findCommitteeAllAdmin(page, pageSize) {
    return this.post({
      url: '/committee/findCommitteeList',
      data: { customizeId: 1 },
      after: (res) => {
        // localStorage.setItem("APP_TOKEN", res.data.message);
        // this.setImg(res.data.data.list, 'titleImg')
        console.log(res.data.data);
        res.data.data.forEach((item) => {
          this.setImg(item.recordList, 'titleImage');
        });
        return res.data.data;
      },
    });
  }
  //查询往届
  async findHistoryVoteArtistList(data) {
    return this.post({
      url: '/customize/findHistoryVoteArtistList',
      data,
      after: (res) => {
        this.setImg(res.data.data, 'artistPortrait');
        return res.data.data;
      },
    });
  }
  //查询往届LIST
  async findHistoryVoteList(data) {
    return this.post({
      url: '/customize/findHistoryVoteList',
      data,
      after: (res) => {
        return res.data.data;
      },
    });
  }
  //收藏
  async addMyFavorites(data) {
    return this.post({
      url: '/favorites/addMyFavorites',
      data,
      after: (res) => {
        return res.data.data;
      },
    });
  }

  //参赛人物详情
  async selectOneArtistPeople(id) {
    return this.post({
      url: '/artist/selectOneArtist',
      data: {
        id,
      },
      after: (res) => {
        this.setImg(res.data.data, 'artistPortrait');
        console.log(res.data.data, 'wwww');
        let data = res.data.data;
        data._artistWorks = JSON.parse(data.artistWorks);
        let IMGURL = process.env.VUE_APP_BASR_IMG_URL;
        console.log(IMGURL);
        let _artistWorks = [];
        if (data._artistWorks && data._artistWorks != 'null') {
          data._artistWorks.forEach((img) => {
            _artistWorks.push(IMGURL + img);
          });
          data.artistPortrait = IMGURL + data.artistPortrait;
          data._artistWorks = _artistWorks;
        }

        return data;
      },
    });
  }
  //查询详情
  async selectNewsFIRST(data) {
    return this.post({
      url: '/news/selectNewsFIRST',
      data,
      after: (res) => {
        return res.data.data; report
      },
    });
  }
  //查询活动详情
  async findDownloadFile(data) {
    return this.post({
      url: '/customize/findDownloadFile',
      data,
      after: (res) => {
        let IMGURL = process.env.VUE_APP_BASR_IMG_URL;
        // res.data.data.contestVideoUrl = IMGURL + res.data.data.contestVideoUrl;
        return res.data.data;
      },
    });
  }
  //查询详情
  async verification(number, licensee) {
    return this.post({
      url: '/certificate/verification',
      data: {
        number,
        licensee,
      },
      after: (res) => {
        return res.data;
      },
    });
  }
  //投票
  async votePc(data) {
    return this.post({
      url: '/artist/votePc',
      data,
      after: (res) => {
        return res.data;
      },
    });
  }
  //下载文件
  async downloadFiles() {
    return this.post({
      url: '/download/file?fileId=11',
      before: (ctx) => {
        // console.log(ctx);
        window.open(ctx.url);
        return Promise.resolve();
      },
      after: (res) => {
        return;
      },
    });
  }
}
export default function install(vue) {
  vue.prototype.api = new Api();
}
